﻿package com.wandian.view.components.ui
{
	import com.greensock.TweenLite;
	import com.wandian.ApplicationFacade;
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.model.AccountProxy;
	import com.wandian.model.vo.HonorVo;
	import com.wandian.model.vo.PlayerVo;
	import com.wandian.model.vo.PropVo;
	import com.wandian.util.ButtonUtil;
	import com.wandian.util.CLZLoadIcon;
	import com.wandian.util.CLZTiming;
	import com.wandian.util.RadioManage;
	import com.wandian.util.TextControl;
	import com.wandian.view.layer.Canvas;

	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	/**   
	* @author long
	* @QQ 108232706
	* @version 1.0   
	*/   
	public class SystemTip extends Object
	{
		private var _global:GameData;
		private var _mcWindowsPanel:Sprite;
		private var _mcPropTip:Sprite;
		private var _useTip:MovieClip;
		private var _mcPlayerTip:Sprite;
		private var _mcFullTip:MaskTipPanel;
		private var _facade:ApplicationFacade;
		private var _honorTip:Sprite;
		private var _accountProxy:AccountProxy;
		private var _mcLevel:LevelManage;

		public function SystemTip()
		{
			this._global=GameData.getInstance();
			this._facade=ApplicationFacade.getInstance();
			this._mcLevel=new LevelManage();
			this._accountProxy=this._facade.retrieveProxy(AccountProxy.NAME) as AccountProxy;
			return;
		} 

		public function setMcWindowsTip(mc:Sprite, isSendClose:Boolean, okNoticeName:String, strTip:String, strTitle:String, obj:Object, isCancel:Boolean, okBtnTip:String, cancelBtnTip:String, countTime:uint=0):void
		{
			var countTimeHandler:Function;
			var okFun:Function;
			var closeFun:Function;
			countTimeHandler=function():void
			{
				countTime--;
				_mcWindowsPanel["conten_txt"].htmlText=strTip + "\n<font size=\'18\' color=\'#ff0000\'>" + GameData.countTime(countTime) + "</font>";
				if (countTime != 0)
				{
					CLZTiming.add(1, countTimeHandler);
				}
				return;
			} 
			;
			okFun=function():void
			{
				if (okNoticeName == CLZNoticeName.GO_VERIFICATION)
				{
					return;
				}
				CLZTiming.remove(countTimeHandler);
				if (isSendClose)
				{
					_facade.sendNotification(okNoticeName, obj, "0");
				}
				else
				{
					_facade.sendNotification(okNoticeName, obj);
				}
				_facade.sendNotification(CLZNoticeName.TIPMEDIATOR_HIDE_WINDOWS_TIP, obj);
				return;
			} 
			;
			closeFun=function():void
			{
				CLZTiming.remove(countTimeHandler);
				if (isSendClose)
				{
					_facade.sendNotification(okNoticeName, obj, "-1");
				}
				_facade.sendNotification(CLZNoticeName.TIPMEDIATOR_HIDE_WINDOWS_TIP, obj);
				return;
			} 
			;
			this.removeMcWindowsTip();
			this._mcWindowsPanel=mc;
			if (isCancel)
			{
				AddBtn.addCurrentFunBtn(this._mcWindowsPanel, okFun, GameData.tip[okBtnTip], 85, 160, "OKBtn", obj);
				AddBtn.addCurrentFunBtn(this._mcWindowsPanel, closeFun, GameData.tip[cancelBtnTip], 267, 160, "CancelBtn", obj);
				AddBtn.addCurrentFunBtn(this._mcWindowsPanel, closeFun, "", 345, 4, "CloseBtn2", obj);
			}
			else
			{
				AddBtn.addCurrentFunBtn(this._mcWindowsPanel, okFun, GameData.tip[okBtnTip], 150, 160, "OKBtn", obj);
			}
			this._mcWindowsPanel["title_txt"].text=strTitle;
			if (countTime == 0)
			{
				this._mcWindowsPanel["conten_txt"].htmlText=strTip;
			}
			else
			{
				CLZTiming.add(1, countTimeHandler);
				this._mcWindowsPanel["conten_txt"].htmlText=strTip + "\n<font size=\'18\' color=\'#ff0000\'>" + GameData.countTime(countTime) + "</font>";
			}
			Texas.I._mcTipView.addChildTo(this._mcWindowsPanel);
			Texas.I._mcTipView.centerXY(this._mcWindowsPanel);
			return;
		} 

		public function removeMcWindowsTip():void
		{
			if (this._mcWindowsPanel == null)
			{
				return;
			}
			if (Texas.I._mcTipView.contains(this._mcWindowsPanel))
			{
				Texas.I._mcTipView.removeChildTo(this._mcWindowsPanel);
				this._mcWindowsPanel=null;
			}

		} 

		public function showPropTipPanel(showType:String, propVo:PropVo):void
		{
			var objData:Object;
			var changeNumHandler:Function;
			var changeGiveIdHandler:Function;
			changeNumHandler=function(event:Event=null):void
			{
				var _loc_2:*=int(_mcPropTip["num_txt"].text);
				objData.num=_loc_2;
				_mcPropTip["sumGold_txt"].text=int(_loc_2 * propVo.price * (propVo.discount / 100)) + GameData.tip["GOLD"];
				return;
			} 
			;
			changeGiveIdHandler=function(event:Event):void
			{
				var _loc_2:*=int(_mcPropTip["giveId_txt"].text);
				objData.arrMid[0]=_loc_2;
				return;
			} 
			;
			objData=new Object();
			objData.arrMid=[];
			objData.type=propVo.pcate;
			objData.giftId=propVo.pframe;
			objData.num=1;
			if (this._mcPropTip != null)
			{
				this.removeSystemTip(this._mcPropTip);
			}
			this._mcPropTip=GameData.getMovieClip("BuyInPorpTip");
			Texas.I._mcTipView.addChild(this._mcPropTip);
			Texas.I._mcTipView.centerXY(this._mcPropTip);
			AddBtn.initBtn(this._mcPropTip, CLZNoticeName.CLOSE_PROP_TIP_WINDOW, AddBtn.CLOSE_TWO, "", 3, 4);
			AddBtn.addCurrentFunBtn(this._mcPropTip, this.okGiveBuyPropGift, GameData.tip["OK"], 213, 163, "Otherbtn", objData);
			this._mcPropTip.addEventListener(Event.CHANGE, changeNumHandler);
			this._mcPropTip["title_txt"].text=GameData.tip["BUYIN_PROP_TITLE"];
			this._mcPropTip["numName_txt"].text=GameData.tip["BUYIN_NUMBER_NAME"] + ":";
			this._mcPropTip["num_txt"].text="1";
			this._mcPropTip["sumGoldName_txt"].text=GameData.tip["SUMGOLD_NAME"] + ":";
			this._mcPropTip["propName_txt"].text=propVo.name;
			CLZLoadIcon.addIcon(this._mcPropTip["pic"], propVo.url, 85, 85, 0, 0, "InitPropIcon", false, false);
			TextControl.initAddSubTxt(this._mcPropTip, this._mcPropTip["num_txt"], this._mcPropTip["add_btn"], this._mcPropTip["sub_btn"], 1, 10);
			this._mcPropTip["num_txt"].restrict="1-9";
			switch (showType)
			{
				case CLZNoticeName.BUYIN_PROP_TIP_WINDOW:
				{
					objData.arrMid[0]=this._global.userInfo.userVo.userid;
					this._mcPropTip["giveName_txt"].text="";
					this._mcPropTip["giveId_txt"].visible=false;
					this._mcPropTip["sendBg_mc"].visible=false;
					break;
				}
				case CLZNoticeName.SEND_PROP_TIP_WINDOW:
				{
					this._mcPropTip["giveName_txt"].text=GameData.tip["GIVE_NUMBER_ID_NAME"] + ":";
					TextControl.initTxtTip(this._mcPropTip["giveId_txt"], GameData.tip["PLEASE_ENTER_NUMBER_ID"]);
					this._mcPropTip["giveId_txt"].restrict="1-9";
					this._mcPropTip["giveId_txt"].addEventListener(Event.CHANGE, changeGiveIdHandler);
					this._mcPropTip["giveId_txt"].visible=true;
					this._mcPropTip["sendBg_mc"].visible=true;
					break;
				}
				default:
				{
					break;
				}
			}
			changeNumHandler();
			return;
		}

		public function okGiveBuyPropGift(param1:Object):void
		{
			this._facade.sendNotification(CLZNoticeName.OK_GIVE_BUY_PROP_GIFT, param1);
			this._facade.sendNotification(CLZNoticeName.CLOSE_PROP_TIP_WINDOW);
			return;
		} 

		public function removePropTip():void
		{
			this.removeSystemTip(this._mcPropTip);
			return;
		} 

		public function showUseTip(param1:Object):void
		{
			var ntime:int;
			var countdownTime:Function;
			var obj:*=param1;
			this.removeUseTip();
			this._useTip=GameData.getMovieClip("UseTipMc");
			var playerVo:*=obj.playerVo;
			var pcate:*=obj.pcate;
			var pframe:*=obj.pframe;
			var propVo:*=GameData.getPropById(pcate, pframe);
			if (obj.tip == null)
			{
				if (playerVo.userid == this._global.userInfo.userVo.userid)
				{
					this._useTip.tip_txt.htmlText=GameData.replaceStrValue(GameData.tip["OK_USE_PROP_TIP_TOME"], "PROP", propVo.name);
				}
				else
				{
					this._useTip.tip_txt.htmlText=GameData.replaceStrValue(GameData.replaceStrValue(GameData.tip["OK_USE_PROP_TIP_TOPLAYER"], "PROP", propVo.name), "NAME", playerVo.name);
				}
			}
			else
			{
				this._useTip.tip_txt.htmlText=obj.tip;
			}
			var radio:RadioManage=new RadioManage([[GameData.USE_GOLD_RADIO, this._useTip.radio1], [GameData.USE_CARD_RADIO, this._useTip.radio2]]);
			radio.addEventListener(Event.CHANGE, this.changeUseHandler);
			var num:*=this._accountProxy.getPropNumById(propVo.pcate, propVo.pframe);
			var msg:*=GameData.replaceStrValue(GameData.replaceStrTipHtml(GameData.tip["USE_GOLD_TIP"]), "GOLD", int(propVo.price * (propVo.discount / 100)));
			this._useTip.radio1_txt.htmlText=GameData.replaceStrValue(msg, "PROP", propVo.name);
			this._useTip.radio2_txt.htmlText=GameData.replaceStrValue(GameData.replaceStrValue(GameData.replaceStrTipHtml(GameData.tip["USE_CARD_TIP"]), "PROP", propVo.name), "NUM", num);
			if (num == 0)
			{
				this._useTip.radio2.visible=false;
				this._useTip.radio2_txt.htmlText="";
				radio.setRadioSelect(GameData.USE_GOLD_RADIO);
				if (pcate == GameData.PROP_PCATE_ID_1)
				{
				}
				if (pframe == GameData.PROP_DEFENCE_KICK_PFRAME_ID)
				{
					countdownTime=function():void
					{
						var _loc_2:*=ntime - 1;
						ntime=_loc_2;
						_useTip.radio2_txt.htmlText=GameData.replaceStrValue(GameData.tip["TICK_TIME_NUM"], "NUM", ntime);
						CLZTiming.remove(countdownTime);
						if (ntime <= 0)
						{
							removeUseTip();
						}
						else
						{
							CLZTiming.add(1, countdownTime);
						}
						return;
					} 
					;
					ntime=int(GameData.config["DEFIND_TICK_TIME"]);
					CLZTiming.add(1, countdownTime);
				}
			}
			else
			{
				this._useTip.radio2.visible=true;
				radio.setRadioSelect(GameData.USE_CARD_RADIO);
			}
			Texas.I._mcTipView.addChild(this._useTip);
			Texas.I._mcTipView.centerXY(this._useTip);
			AddBtn.initBtn(this._useTip, CLZNoticeName.HIDE_USE_SELECTED_TIP, AddBtn.CLOSE_TWO, "", 3, 4);
			var objData:Object;
			AddBtn.addCurrentFunBtn(this._useTip, this.okUseProp, GameData.tip["OK"], 95, 164, "Otherbtn", objData);
			AddBtn.initBtn(this._useTip, CLZNoticeName.HIDE_USE_SELECTED_TIP, AddBtn.CANCEL, GameData.tip["CANCEL"], 236, 164);
			return;
		}

		private function changeUseHandler(event:Event):void
		{
			this._useTip.id=event.target._radioId;
			return;
		} 

		private function okUseProp(param1:Object):void
		{
			param1.type=this._useTip.id;
			this.removeUseTip();
			if (GameData.USE_GOLD_RADIO == param1.type)
			{
				if (param1.price > this._global.userInfo.userVo.gold)
				{
					this._facade.sendNotification(CLZNoticeName.SHOW_MOVE_TIP, {tip: GameData.tip["GAME_GOLD_NOT_ENOUGH"]});
					return;
				}
			}
			this._facade.sendNotification(CLZNoticeName.USE_PROP_TYPE, param1);
			return;
		} 

		public function removeUseTip():void
		{
			this.removeSystemTip(this._useTip);
			return;
		} 

		public function showMoveTip(json:Object):void
		{
			var mcSystemTip:*=GameData.getSprite("SystemTip");
			Texas.I._mcTipView.addChild(mcSystemTip);
			Texas.I._mcTipView.centerXY(mcSystemTip, 0, 0, Canvas.HIDE_MOVE);
			mcSystemTip.alpha=0;
			mcSystemTip["txt"].htmlText=json.tip;
			TweenLite.to(mcSystemTip, 0.4, {y: mcSystemTip.y - 50, alpha: 1, onComplete: this.moveMiddleFinish, onCompleteParams: [mcSystemTip]});
			return;
		} 

		private function moveMiddleFinish(mcSystemTip:Sprite):void
		{
			TweenLite.to(mcSystemTip, 0.4, {y: mcSystemTip.y - 50, alpha: 0.1, delay: 1.5, onComplete: this.removeSystemTip, onCompleteParams: [mcSystemTip]});
			return;
		} 

		public function showOverPlayerTip(playerVo:PlayerVo):void
		{
			if (this._mcPlayerTip == null)
			{
				this._mcPlayerTip=GameData.getSprite("PlayerTip");
			}
			Texas.I._mcTipView.addChild(this._mcPlayerTip);
			this._mcPlayerTip.x=0;
			this._mcPlayerTip.y=GameData.config["stageH"];
			this._mcPlayerTip["rankName_txt"].text=GameData.tip["RANK_NAME"] + ":";
			this._mcPlayerTip["levelName_txt"].text=GameData.tip["GOLDLEVELNAME"] + ":";
			this._mcPlayerTip["idName_txt"].text=GameData.tip["IDNAME"] + ":";
			this._mcPlayerTip["goldName_txt"].text=GameData.tip["GOLD"] + ":";
			this._mcPlayerTip["sumGameName_txt"].text=GameData.tip["SUM_GAME_NUM"] + ":";
			this._mcPlayerTip["winGameName_txt"].text=GameData.tip["WIN_GAME_NUM"] + ":";
			this._mcPlayerTip["rankNum_txt"].htmlText=GameData.replaceStrValue(GameData.tip["PLAYER_TIP_RANK_NUM"], "NUM", playerVo.rank);
			this._mcLevel.updateLevel(this._mcPlayerTip["level_mc"], playerVo.level, false);
			this._mcLevel.playFlash();
			this._mcPlayerTip["uid_txt"].text=playerVo.userid.toString();
			this._mcPlayerTip["name_txt"].text=playerVo.name;
			this._mcPlayerTip["gold_txt"].text=playerVo.money;
			this._mcPlayerTip["sumGame_txt"].text=playerVo.sumGame.toString();
			this._mcPlayerTip["winGame_txt"].text=playerVo.winGame.toString();
			GameData.removeNumChildre(this._mcPlayerTip["icon_mc"]);
			if (playerVo.sex == 1)
			{
				CLZLoadIcon.addIcon(this._mcPlayerTip["icon_mc"], playerVo.icon, 50, 50, 0, 0, "InitPicGirlIcon");
			}
			else
			{
				CLZLoadIcon.addIcon(this._mcPlayerTip["icon_mc"], playerVo.icon, 50, 50, 0, 0, "InitPicBoyIcon");
			}
			TweenLite.to(this._mcPlayerTip, 0.4, {y: int(GameData.config["stageH"]) - this._mcPlayerTip.height});
			return;
		}

		public function hideOutPlayerTip():void
		{
			if (this._mcPlayerTip == null)
			{
				return;
			}
			this._mcLevel.stopFlash();
			TweenLite.to(this._mcPlayerTip, 1, {y: GameData.config["stageH"], onComplete: this.removeSystemTip, onCompleteParams: [this._mcPlayerTip]});
			return;
		}

		public function showFullTip(param1:String, param2:Boolean=false, param3:String="", param4:String=""):void
		{
			this.removeShowFullTip();
			this._mcFullTip=new MaskTipPanel();
			this._mcFullTip.return_btn.visible=false;
			Texas.I._mcTipView.addChild(this._mcFullTip);
			this._mcFullTip["txt"].htmlText=param1;
			this._mcFullTip.showGameTip();
			GameData.playMcAllChild(this._mcFullTip.swfIcon_mc);
			if (param2)
			{
				AddBtn.initBtn(this._mcFullTip, param4, AddBtn.OTHER, param3, 424, 361, null, "Otherbtn");
			}
			return;
		}

		public function removeShowFullTip():void
		{
			if (this._mcFullTip == null)
			{
				return;
			}
			GameData.stopMcAllChild(this._mcFullTip.swfIcon_mc);
			this.removeSystemTip(this._mcFullTip);
			this._mcFullTip=null;
			return;
		}

		public function showHonorTip():void
		{
			var honorProp:Object=null;
			if (this._honorTip == null)
			{
				this._honorTip=GameData.getSprite("HonorTip");
				honorProp=GameData.arrHonorTip.shift();
				if (honorProp == null)
				{
					return;
				}
			}
			else
			{
				return;
			}
			Texas.I._mcTipView.addChild(this._honorTip);
			var prop:*=GameData.getHonorById(honorProp.pcate, honorProp.pframe);
			AddBtn.initBtn(this._honorTip, CLZNoticeName.HIDE_HONOR_TIP, AddBtn.CLOSE_THREE, "", 268, 5);
			AddBtn.addCurrentFunBtn(this._honorTip, this.jsShowHonor, GameData.tip["SHOW"], 193, 116, "BTN2", prop);
			AddBtn.initBtn(this._honorTip, CLZNoticeName.HIDE_HONOR_TIP, AddBtn.OTHER, GameData.tip["IGNORE"], 81, 116, null, "BTN3");
			this._accountProxy.addHonorHandler(prop.pcate, prop.pframe);
			this._honorTip["name_txt"].htmlText=GameData.replaceStrValue(GameData.tip["HONOR_GET_TIP"], "NAME", prop.name);
			this._honorTip["intor_txt"].text=prop.des;
			this._global.userInfo.gold=honorProp.gold;
			this._honorTip.x=0;
			this._honorTip.y=GameData.config["stageH"];
			CLZLoadIcon.addIcon(this._honorTip, prop.url, 85, 85, 15, 18, "InitHonorIcon");
			TweenLite.to(this._honorTip, 0.4, {y: int(GameData.config["stageH"]) - this._honorTip.height});
			return;
		}

		public function jsShowHonor(param1:HonorVo):void
		{
//			JSFUN.shareHonorFunc(param1 as HonorVo);
			this._facade.sendNotification(CLZNoticeName.HIDE_HONOR_TIP);
			return;
		}

		public function hideHonorTip():void
		{
			if (this._honorTip == null)
			{
				return;
			}
			TweenLite.to(this._honorTip, 1, {y: GameData.config["stageH"], onComplete: this.removeSystemTip, onCompleteParams: [this._honorTip]});
			this._honorTip=null;
			this.showHonorTip();
			return;
		}

		public function removeSystemTip(childDisplay:DisplayObjectContainer):void
		{
			if (childDisplay != null)
			{
				if (Texas.I._mcTipView.contains(childDisplay))
				{
					Texas.I._mcTipView.removeChild(childDisplay);
					childDisplay=null;
				}
			}
			return;
		} 

	}
}
